package com.shasselclub.api.v1;

import com.shasselclub.api.v1.service.GetCodeService;
import com.shasselclub.api.v1.service.ValidParamService;
import com.shasselclub.api.v1.valid.MobileForm;
import com.shasselclub.common.constant.ResultModel;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
* @Author: xianyun
*/
@Slf4j
@Api(value = "短信",tags = "短信",description = "1")
@RestController
@RequestMapping("/api/code")
public class CodeApi {
    @Autowired
    private Environment env;
    @Autowired
    private GetCodeService getCodeService;
    @Autowired
    private ValidParamService validParamService;

    @PostMapping(value = "/getCode",produces = "application/json;charset=UTF-8")
    @ApiOperation(value = "获取手机验证码",notes ="获取手机验证码",position = 1,response = ResultModel.class)
    @ResponseBody
    public ResultModel getCode(@Valid MobileForm loginRequest, BindingResult bindingResult, HttpServletRequest request){
        ResultModel resultModel=new ResultModel();
        /**
         * 验证问卷id是否正确
         */
        if (validParamService.validParamForQuestionId(loginRequest.getQuestionId(), resultModel)){
            return resultModel;
        }
        if (getCodeService.getCode(loginRequest, bindingResult, request, resultModel)){
            return resultModel;
        }

        return resultModel;
    }



}
